import cv2 as cv
import numpy as np 

orl = cv.imread("/home/heron/Desktop/linux_notes/python/img/pic001.png")

# 取出单个通道出来
img=orl[:,:,0] 

cv.imshow("img",img)
cv.waitKey()
r,c = img.shape

# 存储8个位平面的掩码
x = np.zeros((r,c,8),dtype = np.uint8)

for i in range(8):
  x[:,:,i] = 2**i

# 存储分解出来的8个位平面
r = np.zeros((r,c,8),dtype = np.uint8)

for i in range(8):
  r[:,:,i] = cv.bitwise_and(img,x[:,:,i])
  mask = r[:,:,i]>0
  r[mask] = 255
  cv.imshow(str(i),r[:,:,i])

cv.waitKey()
cv.destroyAllWindows()
